/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.entities;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;

/**
 *
 * @author mathieumiollan
 */
@NamedQueries({
    @NamedQuery(name = "Acheteur.findLogin", query = "SELECT u FROM Acheteur u WHERE u.login=:login"),     
    @NamedQuery(name = "Acheteur.findByLoginAndPassword", query = "SELECT u FROM Acheteur u WHERE u.login=:login AND u.password=:password"),
    })
@Entity
public class Acheteur implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private String nom;
    private String prenom;
    private String adresse;
    private String login;
    private String password;
    @ManyToMany(cascade={CascadeType.ALL}, fetch=FetchType.EAGER)
    private Collection<Produit> panier = new ArrayList(); 

    public Acheteur() {
    }

    public Acheteur(String nom, String prenom, String adresse, String login, String password) {
        this.nom = nom;
        this.prenom = prenom;
        this.adresse = adresse;
        this.login = login;
        this.password = password;
    }

    public Long getId() {
        return id;
    }

    public String getNom() {
        return nom;
    }

    public Collection<Produit> getPanier() {
        return panier;
    }

    public void setPanier(Collection<Produit> panier) {
        this.panier = panier;
    }

    public void setNom(String nom) {
        this.nom = nom;
    }

    public String getPrenom() {
        return prenom;
    }

    public void setPrenom(String prenom) {
        this.prenom = prenom;
    }

    public String getAdresse() {
        return adresse;
    }

    public void setAdresse(String adresse) {
        this.adresse = adresse;
    }

    public String getLogin() {
        return login;
    }

    public void setLogin(String login) {
        this.login = login;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public void setId(Long id) {
        this.id = id;
    }
    
    public void addProduit(Produit p){
        panier.add(p);
    }
    
    public void removeProduit(Produit p){
        panier.remove(p);
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Acheteur)) {
            return false;
        }
        Acheteur other = (Acheteur) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.entities.Acheteur[ id=" + id + " ]";
    }
    
}
